import axios from 'axios'
import React, { useEffect, useRef, useState } from 'react'

export default function KoaTest() {
  let [data, setData] = useState(null)

  useEffect(() => {
    /*     let url = 'http://localhost:5555/home'
    axios.get(url).then(res => {
      console.log('[ res ]-9', res)
      setData(res.data)
    }) */
  }, [])

  const fetBanner = () => {
    console.log('触发')
    let url = 'http://localhost:5555/banner/list'
    axios.get(url).then(res => {
      console.log('[ res ]-9', res)
      setData(res.data)
    })
  }
  const userName = useRef(null)
  const password = useRef(null)

  const login = () => {
    let userNameV = userName.current.value
    let passwordV = password.current.value
    let p = { name:userNameV, pwd:passwordV }

    let url = 'http://localhost:5555/login'
    axios.post(url,p).then(res => {
      console.log('[ res ]-9', res)
      setData(res.data)
    }) 
  }

  return (
    <div>
      <button onClick={() => fetBanner()}>获取banner</button>
      <input type="text" ref={userName} />
      <input type="password" ref={password}></input>
      <button onClick={() => login()}>登录</button>
    </div>
  )
}
